package com.dong.common;

import java.io.Serializable;

public class Result implements Serializable {

    private Integer code;
    private String msg;

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Result success() {
        return new Result(ResultCode.SUCCESS.code, ResultCode.SUCCESS.desc);
    }

    public static Result error(String errorMsg) {
        return new Result(ResultCode.ERROR.code, null != errorMsg ? errorMsg : ResultCode.ERROR.desc);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }

    public enum ResultCode {
        SUCCESS(200, "请求成功"),
        NO_LOGIN(403, "用户未授权"),
        ERROR(500, "服务器内部错误");

        Integer code;
        String desc;

        ResultCode(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }


    }
}
